<%--
  Created by IntelliJ IDEA.
  User: zhangDongFei
  Date: 2020/11/26
  Time: 14:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>基本资料</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" charset="GBK">
    <script src="${pageContext.request.contextPath}/jquery-3.5.1.min.js" charset="GBK"></script>
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <link href="${pageContext.request.contextPath}/toastr-master/toastr.min.css" rel="stylesheet"/>
    <script src="${pageContext.request.contextPath}/toastr-master/toastr.min.js" charset="GBK"></script>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.min.js"></script>
</head>
<style>
    #left {
        float: left;
        width: 50%;
    }

    #right {
        float: right;
        width: 50%;
    }
</style>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>个人信息</legend>
</fieldset>
<div id="left">
    <div class="layui-card">
        <div class="layui-card-header">可修改信息</div>
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="updateInformation" id="updateInformation">
                <input type="hidden" name="id" >
                <input type="hidden" name="imgpath" id="avatar" >
                <div class="layui-upload">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" src="${url}" id="demo1" style="width: 100px;height: 80px">
                        <p id="demoText"></p>
                    </div>
                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                </div>
                <hr class="layui-bg-green">
                <input type="text" style="display: none" name="id" value="${id}">
                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="iphone" class="layui-input" lay-verify="required|phone">
                    </div>
                </div>
                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-inline">
                        <textarea type="text" name="address" class="layui-input" lay-verify="required"></textarea>
                    </div>
                </div>
                <br>
                <div class="layui-form-item layui-col-md-offset4" style="margin-top: 5px">
                    <button lay-submit lay-filter="updateBtn" class="layui-btn">修改资料</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="right">
    <div class="layui-card">
        <div class="layui-card-header">基本信息</div>
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="information" id="information" style="margin-top: 5px">
                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="id" class="layui-input" disabled>
                    </div>
                </div>

                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" class="layui-input" disabled>
                    </div>
                </div>

                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">所属部门</label>
                    <div class="layui-input-inline ">
                        <input type="text" name="dname" class="layui-input" disabled>
                    </div>
                </div>

                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">入职时间</label>
                    <div class="layui-input-inline ">
                        <input type="text" name="rzdate" class="layui-input" disabled>
                    </div>
                </div>

                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">职位</label>
                    <div class="layui-input-inline ">
                        <input type="text" name="rname" class="layui-input" disabled>
                    </div>
                </div>

                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="iphone" class="layui-input" disabled>
                    </div>
                </div>

                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">身份证号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="idcard" class="layui-input" disabled>
                    </div>
                </div>

                <div class="layui-form-item layui-row" style="margin-bottom: 2px">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-inline">
                        <textarea type="text" name="address" class="layui-input" disabled></textarea>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

</body>
<script>
    layui.use(['upload', 'form'], function () {
        var $ = layui.jquery;
        var upload = layui.upload;
        var form = layui.form;

        $(function () {
            getInformation();
        })

        // 发送ajax请求当前登录人的信息
        function getInformation() {
            $.ajax({
                url: '${pageContext.request.contextPath}/YG/quer',
                type: 'post',
                async: false,
                dataType: 'JSON',
                success: function (result) {
                    form.val('information', result)
                    form.val('updateInformation', result)
                    $('#demo1').attr('src',result.imgpath );
                }
            })
        }


        //修改手机号的地址表单提交
        form.on('submit(updateBtn)', function (data) {
            $.ajax({
                url: '${pageContext.request.contextPath}/YG/upd',
                data: data.field,
                async: false,
                type: 'post',
                dataType: 'JSON',
                success: function (result) {
                    if (result > 0) {
                        getInformation();
                        layer.msg("修改成功");
                    } else {
                        layer.msg("修改失败")
                    }
                }
            })
            return false;
        })

        /*    //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , acceptMime: 'image/!*'
                , url: '/YG/upl' //改成您自己的上传接口
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return toastr.error("头像上传失败")
                    } else {
                        //上传成功
                        return toastr.success("头像上传成功")
                    }
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });*/
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '${pageContext.request.contextPath}/YG/upl' //上传接口
            ,done: function(res){
                alert(res);
                alert(res.data);
                //上传完毕回调
                //如果上传失败
                if(res.code == 0){
                    var src=res.data;
                    $("#avatar").val(src);
                    $('#demo1').attr('src',src );

                }else
                {
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //请求异常回调
                alert("请求异常回调")
            }
        });
    })
</script>
</html>

